// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：
// https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F

const install = (Vue, vm) => {
	vm.$u.api = {};
	const get = vm.$u.get;
	const post = vm.$u.post;
	const put = vm.$u.put;
	const patch = vm.$u.patch;
	
	const index = (params = {}) => get('/api/index', params);
	
	const authLogin = params => post('/api/auth/login', params);
	const authLogout = () => post('/api/auth/logout');
	const authRegister = params => post('/api/auth/register', params);
	
	const userInfo = params => get('/api/user', params);
	const userInfoUpdate = params => put('/api/user', params);
	const userAvatar = params => patch('/api/user/avatar', params);
	
	const authOssToken = params => get('/api/auth/oss/token', params);

	const getIndex = params => get('/api/index', params);
	
	const goodsInfo = params => get(`/api/goods/${params}`);
	const goodsCollected = params => post(`/api/collects/goods/${params}`);
	const getGoods = (params={}) => get('/api/goods', params);
	
	const cartAdd = params => post(`/api/carts`, params);
	const cartList = params => get('/api/carts');
	

	vm.$u.api = {
		index,
		authLogin,
		authLogout,
		authRegister,
		userInfo,
		userInfoUpdate,
		userAvatar,
		authOssToken,
		getIndex,
		goodsInfo,
		goodsCollected,
		getGoods,
		cartAdd,
		cartList
	};
}

export default {
	install
}
